home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Source.bin / HorizontalLine.java < prev    next >
Text File  |  1998-10-02  |  3KB  |  97 lines

  1. package symantec.itools.awt.shape;
  2.  
  3. import java.beans.PropertyVetoException;
  4. import java.awt.Dimension;
  5. import java.awt.Rectangle;
  6.  
  7. //  07/30/97    LAB    Updated version to 1.1.  Line can now be 1 pixel thick if it is
  8. //                    in BEVEL_LINE or BEVEL_NONE mode.
  9. //  08/13/97    LAB    Overrode setBevelStyle to reshape the component to have a thickness
  10. //                    of two pixels if the bevel style was rasied or lowered.  Addresses Mac
  11. //                    Bug #3571
  12. //    10/01/98    EB  Overrode getMinimumSize and getPreferredSize
  13.  
  14. /**
  15.  * This is a horizontal line component.
  16.  * @version 1.2, October 1, 1998
  17.  * @author Symantec
  18.  */
  19. public class HorizontalLine extends Rect
  20. {
  21.     /**
  22.      * Constructs a default HorizontalLine. The line height is 2.
  23.      */
  24.     public HorizontalLine()
  25.     {
  26.         height = 2;
  27.     }
  28.  
  29.     /**
  30.      * Sets the border style of the shape.
  31.      * @see symantec.itools.awt.shape.Shape#getBevelStyle
  32.      *
  33.      * @exception PropertyVetoException
  34.      * if the specified property value is unacceptable
  35.      */
  36.     public void setBevelStyle(int s) throws PropertyVetoException
  37.     {
  38.         if(style != s)
  39.         {
  40.             super.setBevelStyle(s);
  41.             Rectangle r = getBounds();
  42.  
  43.             reshape(r.x, r.y, r.width, r.height == 1 ? 1 : 2);
  44.             validate();
  45.         }
  46.     }
  47.     /**
  48.      * Moves and/or resizes this component.
  49.      * This is a standard Java AWT method which gets called to move and/or
  50.      * resize this component. Components that are in containers with layout
  51.      * managers should not call this method, but rely on the layout manager
  52.      * instead.
  53.      *
  54.      * @param x horizontal position in the parent's coordinate space
  55.      * @param y vertical position in the parent's coordinate space
  56.      * @param width the new width
  57.      * @param height the new height
  58.      */
  59.     public void reshape(int x, int y, int width, int height)
  60.     {
  61.         this.width = width;
  62.  
  63.         //Allow a 1 pixel height if the bevel style is line or none.
  64.         if (height == 1 && (style == BEVEL_LINE || style == BEVEL_NONE))
  65.             this.height = 1;
  66.         else
  67.             this.height = 2;
  68.  
  69.         super.reshape(x, y, width, this.height);
  70.     }
  71.  
  72.      /**
  73.      * Returns the minimum dimensions to properly display this component.
  74.      * This is a standard Java AWT method which gets called to determine
  75.      * the minimum size of this component.
  76.      * @see #getPreferredSize
  77.      */
  78.     public Dimension getMinimumSize()
  79.     {
  80.         return new Dimension(2, 1);
  81.     }
  82.  
  83.     /**
  84.      * Returns the recommended dimensions to properly display this component.
  85.      * This is a standard Java AWT method which gets called to determine
  86.      * the recommended size of this component.
  87.      *
  88.      * @see java.awt.Component#minimumSize
  89.      */
  90.     public Dimension getPreferredSize()
  91.     {
  92.         Dimension dim = getSize();
  93.         Dimension min = getMinimumSize();
  94.         return new Dimension(Math.max(dim.width, min.width), Math.max(dim.height, min.height));
  95.     }
  96. }
  97.